package ysu.sxm.ptjc.Controller;

import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import ysu.sxm.ptjc.Domin.DailyPassRate;
import ysu.sxm.ptjc.Domin.MonthQualified;
import ysu.sxm.ptjc.Domin.MonthQualifiedInfo;
import ysu.sxm.ptjc.Service.MonthQualifiedService;

import java.sql.Date;
import java.util.List;

@RestController
public class MonthQualifiedServlet {
    @Autowired
    MonthQualifiedService monthQualifiedService;
    @PostMapping(path = "/qualified")
    public String test_week(@RequestBody MonthQualified m){
        List<MonthQualifiedInfo> monthQualifiedInfos;
        if(m.getWeek()!=null&&m.getWeek().size() != 0){
            monthQualifiedInfos  = monthQualifiedService.week(m);
        }else if(m.getMonth()!=null){
            monthQualifiedInfos = monthQualifiedService.month(m);
        }
        else
            return null;
        return JSONArray.toJSONString(monthQualifiedInfos);
    }
    @PostMapping(path = "/top")
    public String test_month(@RequestBody  String day ){
        day = day.substring(0,day.length()-1);
        Date date=null;
        if(day!=null) {
            date = Date.valueOf(day);
        }
        List<DailyPassRate> dailyPassRates = monthQualifiedService.dailypassrate(date);
        return JSONArray.toJSONString(dailyPassRates);
    }
}